package com.itheima.a01mybytestream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteStreamDemo2 {
    public static void main(String[] args) throws IOException {
        //拷贝文件时一次读取一个字节太慢了
        //现在熟悉一下一次读取多个字节
        //其实就是在读取时给read传递数组，此时read会尽可能的读取数据装满数组

        //先读在写
        FileInputStream fis = new FileInputStream("D:\\Java\\a.txt");
        FileOutputStream fos = new FileOutputStream("myio\\a.txt");

        byte[] buf = new byte[2];

        //循环读取并写入
        int b;
        while ((b = fis.read(buf)) != -1) {
            //读多少写多少
            fos.write(buf,0,b);
        }

        //释放资源，注意先开的后关
        fos.close();
        fis.close();
    }
}
